package com.report.service;

import com.report.dto.Response;
import com.report.entity.AccountBookData;
import com.report.repository.AccountBookDataRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

@Service
public class AccountBookService {

    @Resource
    private AccountBookDataRepository accountBookDataRepository;


    public Response save(AccountBookData accountBookData) {
        accountBookDataRepository.upsert(accountBookData);
        Response response = new Response();
        response.setStatus("success");
        response.setMessage("success");
        return response;
    }

    public Response get(AccountBookData accountBookData) {
        Optional<AccountBookData> data = accountBookDataRepository.findByMenuAndSjxmbhAndAuditCompanyUsccAndTypeAndTableName(accountBookData.getMenu(), accountBookData.getSjxmbh(), accountBookData.getAuditCompanyUscc(), accountBookData.getType(), accountBookData.getTableName());
        Response response = new Response();
        response.setStatus("success");
        response.setMessage("success");
        response.setData(data.isPresent() ? data.get() : null);
        return response;
    }

}
